
module.exports = function ($scope, RequestService,$localStorage,modelService,$state,commonConfig,$modal,$stateParams) {
    $scope.User = $localStorage.get('cloud');
    //获取当前APP
    RequestService.Request(commonConfig.cloudApi+'cloud/app/{id}?appId='+$stateParams.id+'&tenantId='+$scope.User.detail.tenantId,'GET').then(function(response){
        // console.log(response);
        $scope.Apps = response;
    },function(error){
        console.log(error);
    });
    $scope.getList = function(page){
        //获取当前用户APP列表
        RequestService.Request(commonConfig.cloudApi+'cloud/appcommonlyfunction?appId='+$stateParams.id+'&pageNum='+page+'&pageSize=10&orderBy=id%20asc','GET').then(function(res){
            console.log(res);
            $scope.CommonApps = res.list;
            //分页控制
            $scope.maxSize = 5;
            $scope.totalItems = res.total;  //总数量
            $scope.totalPages = res.pages;   //总页数
            $scope.pageSize = 10; //每页显示数量
            $scope.currentPage = res.pageNum;
            $scope.PageNum = null;  //输入跳转
        },function(error){
            console.log(error);
        });
    };
    $scope.getList(1); //默认获取第一页数据

    //选中数组
    $scope.checkedArry = [];
    //全选功能
    $scope.checkAll = function () {
        if ($scope.check_all) {
            $scope.checkedArry = [];
            angular.forEach($scope.CommonApps, function (i) {
                i.checked = true;
                $scope.checkedArry.push(i.id);
            });
        } else {
            angular.forEach($scope.CommonApps, function (i) {
                i.checked = false;
                $scope.checkedArry = [];
            });
        }
    };
    //单选功能
    $scope.checkOne = function () {
        angular.forEach($scope.CommonApps, function (i) {
            var index = $scope.checkedArry.indexOf(i.id);
            if (i.checked && index === -1) {
                $scope.checkedArry.push(i.id);
            } else if (!i.checked && index !== -1) {
                $scope.checkedArry.splice(index, 1);
            }
        });

        if ($scope.CommonApps.length === $scope.checkedArry.length) {
            $scope.check_all = true;
        } else {
            $scope.check_all = false;
        }
    };
    //数据删除
    $scope.delete = function () {
        var list = $scope.checkedArry;
        console.log(list);
        RequestService.Request(commonConfig.cloudApi+'cloud/appcommonlyfunction?list='+list,'DELETE').then(function (res) {
            console.log(res);
            $scope.checkedArry = [];
            $scope.getList($scope.currentPage);
        }, function (error) {
            console.log(error);
        });
    };
    //分页跳转
    $scope.goPage = function(){
        // console.log($scope.currentPage);
        $scope.getList($scope.currentPage);
    };
    //手动输入跳转
    $scope.goPage2 = function(){
        // console.log($scope.PageNum);
        $scope.getList($scope.PageNum);
    };
    //开启常用应用编辑模态框
    $scope.openModel = function (data) {
        var modalInstance = $modal.open({
            templateUrl: './views/DeveloperPlatform/DeveloperUser/DeveloperApps/CommonAppsEdit.html',
            controller: require('./CommonAppsEditCtrl'),
            size: "md",
            windowClass:'modelClass',
            resolve: {  //将数据作为对象传入控制器中
                data: function () {
                    return data || null;
                }
            }
        });
        modalInstance.result.then(function (res) {
            //$modalInstance.close();调用的方法
            $scope.getList($scope.currentPage);
        }, function () {
            // $scope.getSurveyList();
            //$modalInstance.dismiss();调用的方法
        });
    };

};